class Solution {
public:
    #旋转矩阵
    void rotate(vector<vector<int>>& matrix) {
        int temp;
        int n=matrix.size();
        for(int i=0;i<n/2;i++){
            for(int j=i;j<n-i-1;j++){
                temp=matrix[i][j];
                matrix[i][j]=matrix[n-j-1][i];
                matrix[n-j-1][i]=matrix[n-1-i][n-j-1];
                matrix[n-1-i][n-j-1]=matrix[j][n-1-i];
                matrix[j][n-1-i]=temp;
            }
        }
    }

    #对角线遍历
    vector<int> findDiagonalOrder(vector<vector<int>>& matrix) {
        int direction=1;
        vector<int> V;
        if(!matrix.size()) return V;
        V.push_back(matrix[0][0]);
        int i=0,j=0,tr=matrix.size(),tc=matrix[0].size();
        while(i<tr-1||j<tc-1){
            if(direction){
            if(i==0&&j<tc-1){
                V.push_back(matrix[i][++j]);
                direction=0;
            }
            else if((i==0&&j==tc-1)||j==tc-1){
                V.push_back(matrix[++i][j]);
                direction=0;
            }
            else V.push_back(matrix[--i][++j]);
            }
            else if(!direction){
            if(j==0&&i<tr-1){
                V.push_back(matrix[++i][j]);
                direction=1;
            }
            else if((i==tr-1&&j<tc-1)||(j==0&&i==tr-1)){
                V.push_back(matrix[i][++j]);
                direction=1;
            }
            else V.push_back(matrix[++i][--j]);
            }
        }
        return V;
    }
};